package com.tool.util;

import java.io.PrintStream;

public class StringUtil
{
  public static String getCamel(String name)
  {
    name = name.toLowerCase();
    String[] tmps = name.split("_");
    if (tmps.length == 1)
    {
      return name;
    }
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < tmps.length; i++)
    {
      if (i == 0)
      {
        buf.append(tmps[i]);
      }
      else {
        String tmp = tmps[i];
        buf.append(tmp.substring(0, 1).toUpperCase()).append(tmp.substring(1));
      }
    }
    return buf.toString();
  }

  public static String getBeanName(String name)
  {
    name = name.toLowerCase();
    String[] tmps = name.split("_");
    if (tmps.length == 1)
    {
      return name.substring(0, 1).toUpperCase() + name.substring(1);
    }
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < tmps.length; i++)
    {
      String tmp = tmps[i].toLowerCase();
      buf.append(tmp.substring(0, 1).toUpperCase()).append(tmp.substring(1));
    }
    return buf.toString();
  }

  public static String lowerFirst(String name)
  {
    return name.substring(0, 1).toLowerCase() + name.substring(1);
  }

  public static boolean isEmptyString(String str)
  {
    return (str == null) || ("".equals(str));
  }

  public static String trimSql(String sql)
  {
    sql = sql.trim();
    if (sql.endsWith(";"))
    {
      sql = sql.substring(0, sql.length() - 1);
    }
    return sql.toUpperCase();
  }

  public static void main(String[] args)
  {
    System.out.println(trimSql("select * from user;"));
  }
}